<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class User_model extends MY_Model
{
	public $soft_delete = FALSE;

	public $_table = TABLE_ADMIN;

	public $primary_key = 'adminid';

	public $return_type = 'array';

	public $select_field = 'adminid,adminname,password,encrypt,lastloginip,lastlogintime,email,realname,tel';

    function login($user,$pwd)
    {
       $sql="select * from ".$this->db->dbprefix.TABLE_ADMIN." where adminname=\"$user\"";
       $res=$this->db->query($sql)->row_array();
       if($res && $res['password']==$pwd)
       return $res;
       else
       return FALSE;
    }
	

    function add($pid,$title,$control,$method,$url)
    {
      //插入pid 和 title
      $data=array('pid'=>$pid,'title'=>$title,'c'=>$control,'a'=>$method,'url'=>$url);
      $res=$this->db->insert('qp_admin_role',$data);
      if($res)
         $new_id=$this->db->insert_id();
      $sql="select * from qp_admin_role where id=".$pid;
      $query=$this->db->query($sql);
      if($query->num_rows>0)
      {
         $parent=$query->row_array();
         $new_path=$parent['path'].',$'.$new_id.'$';
      }else
      {
         $new_path='$'.$new_id.'$';
      }
      $new_depth=count(explode(',',$new_path))-1;
      $u_data=array('depth'=>$new_depth,'path'=>$new_path);
      $this->db->where('id',$new_id);
      $this->db->update('qp_admin_role',$u_data);
      return ($this->db->affected_rows()>0) ? TRUE : FALSE ;
    }
    function edit_menumes($id){
    	$mid=trim($id);
    	if($mid != ''){
    		$sql="select * from qp_admin_role where id=".$mid;
    		$res=$this->db->query($sql)->result_array();
      		return $res;
    	}
    }
}